package com.joolun.web.controller.tennis;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.tennis.domain.Coach;
import com.joolun.tennis.service.ICoachService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 教练Controller
 * 
 * @author www.joolun.com
 * @date 2022-03-08
 */
@RestController
@RequestMapping("/tennis/coach")
public class CoachController extends BaseController
{
    @Autowired
    private ICoachService coachService;

    /**
     * 查询教练列表
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:list')")
    @GetMapping("/list")
    public TableDataInfo list(Coach coach)
    {
        startPage();
        List<Coach> list = coachService.selectCoachList(coach);
        return getDataTable(list);
    }
    /**
     * 查询所有教练列表
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:list')")
    @GetMapping("/allList")
    public AjaxResult allList(Coach coach)
    {
        List<Coach> list = coachService.selectCoachList(coach);
        return AjaxResult.success(list);
    }

    /**
     * 查询所有教练列表
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:list')")
    @GetMapping("/clubList")
    public AjaxResult clubList(@RequestParam("clubId") Long clubId)
    {
        List<Coach> list = coachService.selectCoachListByClubId(clubId);
        return AjaxResult.success(list);
    }

//    /**
//     * 导出教练列表
//     */
//    @PreAuthorize("@ss.hasPermi('tennis:coach:export')")
//    @Log(title = "教练", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(Coach coach)
//    {
//        List<Coach> list = coachService.selectCoachList(coach);
//        ExcelUtil<Coach> util = new ExcelUtil<Coach>(Coach.class);
//        return util.exportExcel(list, "coach");
//    }

    /**
     * 获取教练详细信息
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(coachService.selectCoachById(id));
    }

    /**
     * 新增教练
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:add')")
    @Log(title = "教练", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Coach coach)
    {
        return toAjax(coachService.insertCoach(coach));
    }

    /**
     * 修改教练
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:edit')")
    @Log(title = "教练", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Coach coach)
    {
        return toAjax(coachService.updateCoach(coach));
    }

    /**
     * 删除教练
     */
    @PreAuthorize("@ss.hasPermi('tennis:coach:remove')")
    @Log(title = "教练", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coachService.deleteCoachByIds(ids));
    }
}
